import java.util.Scanner;

public class Queue1 {
    public static void main(String[] args) {
        methodClass q = new methodClass(3);
        System.out.println("----------------------------------");
        System.out.println("1:增加用户");
        System.out.println("2:查看全部用户");
        System.out.println("3:抽取用户");
        System.out.println("4:退出程序");
        System.out.println("----------------------------------");
        boolean isFlag = true;
        Scanner scanner = new Scanner(System.in);
        char a = ' ';
        while (isFlag) {
            a = scanner.next().charAt(0);
            switch (a) {
                case '1':
                    System.out.print("请输出一个数:");
                    q.addQueue1(scanner.nextInt());
                    System.out.println("----------------");
                    break;
                case '2':
                    System.out.println("----------------");
                    q.showQueue();
                    System.out.println("----------------");
                    break;
                case '3':
                    q.getQueueHead();
                    break;
                case '4':
                    isFlag = false;
                    System.out.println("程序结束！！");
                    break;
            }
        }

    }
}
class methodClass{
    private int maxSize;
    private int font;
    private int rear;
    private int [] arr;

    public methodClass(int maxSize) {
        this.maxSize = maxSize;
        arr= new int[maxSize];
    }

    public void addQueue1(int n){
        if(isFull()){
            System.out.println("队列已满");
            return;
        }
        arr[rear]=n;
        rear = (rear+1)%maxSize;
    }
    public boolean isFull(){
        return (rear+1)%maxSize==font;
    }

    public boolean isEmpty(){
        return rear==font;
    }
    public void showQueue(){
      if(isEmpty()){
          System.out.println("队列为空");
          return;
      }
      for(int i=font;i<font+(rear+maxSize-font)%maxSize;i++){
          System.out.println(arr[i%maxSize]);
      }
    }
    public void getQueueHead(){
        if(isEmpty()){
            System.out.println("队列为空");
            return;
        }
        System.out.println(arr[font]+"被移除队列");
        font=(font+1)%maxSize;
    }
}

